/**
 * @file skoll.tools.tooltips.js
 * @author Alejandro Dario Simi
 * @date $Date: 2014-05-04 01:33:52 +0000 (Sun, 04 May 2014) $
 *
 * $Id: skoll.tools.tooltips.js 111 2014-05-04 01:33:52Z daemonraco@gmail.com $
 * $URL: http://wcomix.googlecode.com/svn/trunk/skins/Skoll/js/skoll.tools.tooltips.js $
 */

/**
 * Skoll skin modal windows manager.
 */
Skoll.tools.ToolTips = {
	//
	// Protected properties.
	_x: 0,
	_y: 0,
	//
	// Public methods.
	close: function() {
		$("#SkollToolTip").addClass("Bermuda");
	},
	open: function(html) {
		if ($("#SkollToolTip").length == 0) {
			$("body").append('<div id="SkollToolTip" class="ToolTip Bermuda"></div>');

			$("body").on("click", function(e) {
				if (!$("#SkollToolTip").is(e.target) && $("#SkollToolTip").has(e.target).length === 0) {
					Skoll.tools.ToolTips.close();
				}
			});
		}

		$("#SkollToolTip").html(html);
		$("#SkollToolTip").removeClass("Bermuda");
		Skoll.tools.ToolTips._setCssPostion();
	},
	openFromUrl: function(url) {
		Skoll.tools.log("ToolTips.openFromUrl(): url '" + url + "'");

		$.ajax({
			url: url,
			success: function(html) {
				Skoll.tools.log("ToolTips.openFromUrl(): opening tooltip");
				Skoll.tools.ToolTips.open(html);
			}
		});
	},
	setPostion: function(x, y) {
		Skoll.tools.ToolTips._x = x;
		Skoll.tools.ToolTips._y = y;

		if ($("#SkollToolTip").length != 0 && !$("#SkollToolTip").hasClass("Bermuda")) {
			Skoll.tools.ToolTips._setCssPostion();
		}
	},
	//
	// Protected methods.
	_setCssPostion: function() {
		$("#SkollToolTip").css({
			left: Skoll.tools.ToolTips._x + "px",
			top: Skoll.tools.ToolTips._y + "px"
		});
	}
};